Personal tools

Lua/Server/Vehicle/Static Functions/Create

From JC2-MP Documentation

< Lua‎ | Server‎ | Vehicle
Jump to: navigation, search

Returns    Vehicle
Prototype    Vehicle.Create(number, Vector3, Angle)
Description    No description


Description

Spawns a vehicle with a model id at a position and angle.

Example

function PlayerChat(args)
	if args.text == "/spawn" then
		-- Spawn a Cavallo at the player.
		Vehicle.Create(2, args.player:GetPosition(), Angle(0, 0, 0))
		return false
	end
	return true
end
 
Events:Subscribe("PlayerChat", PlayerChat)





Returns    Vehicle
Prototype    Vehicle.Create(table)
Description    No description


Description

Spawns a vehicle using an argument table.

The following arguments are supported:

  • number model_id
  • Vector3 position
  • Angle angle
  • string template (List can be found here)
  • string decal (List can be found here)
  • number health
  • Color tone1
  • Color tone2
  • boolean enabled
  • World world
  • number mass
  • Vector3 linear_velocity
  • Vector3 angular_velocity
  • boolean invulnerable

Example

  1. PlayerChat = function(args)
  2. 	local words = args.text:split(" ")
  3.  
  4. 	if words[1] == "/spawn" then
  5. 		if words[2] then
  6. 			local spawnArgs = {}
  7. 			spawnArgs.position = args.player:GetPosition()
  8. 			spawnArgs.angle = args.player:GetAngle()
  9. 			spawnArgs.model_id = tonumber(words[2])
  10. 			spawnArgs.world = args.player:GetWorld()
  11. 			spawnArgs.tone1 = Color(255, 80, 80)
  12. 			spawnArgs.tone2 = Color(200, 100, 100)
  13.  
  14. 			Vehicle.Create(spawnArgs)
  15. 		else
  16. 			args.player:SendChatMessage("Use: /spawn modelid", Color(200, 100, 100))
  17. 		end
  18.  
  19. 		return false
  20. 	end
  21.  
  22. 	return true
  23. end
  24.  
  25. Events:Subscribe("PlayerChat", PlayerChat)